package com.ddf.springdata.jpa.entity;

import com.ddf.springdata.jpa.config.MyAuditAware;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * @author DDf on 2018/9/29
 * @MappedSuperclass 定义实体类所公用属性的超类，映射超类不会生成单独的表，它的映射信息作用于继承自它的实体类。
 * @EntityListeners(AuditingEntityListener.class) 提供对@CreatedDate。@LastModifiedDate等注解的支持，该功能需要依赖spring-aspects
 *  @CreatedBy与@LastModifiedBy的支持请参见 {@link MyAuditAware}
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@Getter
@Setter
@ToString
public class BaseDomain {
    @Id
    @GeneratedValue
    @GenericGenerator(name = "increment", strategy = "increment")
    private Integer id;

    @CreatedBy
    @Column(name = "CREATE_BY")
    private String createBy;

    @CreatedDate
    @Column(name = "CREATE_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @LastModifiedBy
    @Column(name = "MODIFY_BY")
    private String modifyBy;

    @LastModifiedDate
    @Column(name = "MODIFY_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifyTime;

    @Column(name = "REMOVED", columnDefinition = "default 0")
    private Integer removed;

    @Column(name = "VERSION", columnDefinition = "default 0")
    private Integer version;
}
